package cn.hou.java.designpattern._16cor;

public class Test {
	public static void main(String[] args) {
		CarHandler head=new CarHeadHandler();
		CarHandler body=new CarBodyHandler();
		CarHandler foot=new CarFootHandler();
		//提前设置组装顺序,即职责链执行顺序,由于set方法中返回了下一步的职责类,所以可以一直设置
		head.setNextCarHandler(body).setNextCarHandler(foot);
		//调用第一个链首,开始职责
		head.HandlerCar();
		System.out.println("------------");
		//改变顺序,清空之前的顺序,防止死循环
		foot.setNextCarHandler(null);
		body.setNextCarHandler(null);
		head.setNextCarHandler(null);
		foot.setNextCarHandler(body).setNextCarHandler(head);
		foot.HandlerCar();
	}

}
